using System;
using System.Collections.Specialized;
using GetTogether.RichText.Converter.Image;

namespace GetTogether.RichText.Converter.Html
{

	
	public class RtfHtmlConvertSettings
	{

		
		public const string DefaultDocumentHeader =
			"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//DE\" \"http://www.w3.org/TR/html4/loose.dtd\">";
		public const string DefaultDocumentCharacterSet = "UTF-8";

		// regex souce: http://msdn.microsoft.com/en-us/library/aa159903.aspx
		public const string DefaultVisualHyperlinkPattern =
			@"[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*";

		
		public RtfHtmlConvertSettings() :
			this( new RtfVisualImageAdapter(), RtfHtmlConvertScope.All )
		{
		} // RtfHtmlConvertSettings

		
		public RtfHtmlConvertSettings( RtfHtmlConvertScope convertScope ) :
			this( new RtfVisualImageAdapter(), convertScope )
		{
		} // RtfHtmlConvertSettings

		
		public RtfHtmlConvertSettings( IRtfVisualImageAdapter imageAdapter ) :
			this( imageAdapter, RtfHtmlConvertScope.All )
		{
		} // RtfHtmlConvertSettings

		
		public RtfHtmlConvertSettings( IRtfVisualImageAdapter imageAdapter, RtfHtmlConvertScope convertScope )
		{
			if ( imageAdapter == null )
			{
				throw new ArgumentNullException( "imageAdapter" );
			}

			this.imageAdapter = imageAdapter;
			ConvertScope = convertScope;
			VisualHyperlinkPattern = DefaultVisualHyperlinkPattern;
		} // RtfHtmlConvertSettings

		
		public IRtfVisualImageAdapter ImageAdapter
		{
			get { return imageAdapter; }
		} // ImageAdapter

		
		//public RtfHtmlConvertScope ConvertScope { get; set; }
        private RtfHtmlConvertScope _ConvertScope;

        public RtfHtmlConvertScope ConvertScope
        {
            get { return _ConvertScope; }
            set { _ConvertScope = value; }
        }

		
		public bool HasStyles
		{
			get { return styles != null && styles.Count > 0; }
		} // HasStyles

		
		public RtfHtmlCssStyleCollection Styles
		{
			get { return styles ?? ( styles = new RtfHtmlCssStyleCollection() ); }
		} // Styles

		
		public bool HasStyleSheetLinks
		{
			get { return styleSheetLinks != null && styleSheetLinks.Count > 0; }
		} // HasStyleSheetLinks

		
		public StringCollection StyleSheetLinks
		{
			get { return styleSheetLinks ?? ( styleSheetLinks = new StringCollection() ); }
		} // StyleSheetLinks

		
		public string DocumentHeader
		{
			get { return documentHeader; }
			set { documentHeader = value; }
		} // DocumentHeader

		
		//public string Title { get; set; }
        private string _Title;

        public string Title
        {
            get { return _Title; }
            set { _Title = value; }
        }

		
		public string CharacterSet
		{
			get { return characterSet; }
			set { characterSet = value; }
		} // CharacterSet

		
		//public string VisualHyperlinkPattern { get; set; }
        private string _VisualHyperlinkPattern;

        public string VisualHyperlinkPattern
        {
            get { return _VisualHyperlinkPattern; }
            set { _VisualHyperlinkPattern = value; }
        }

		
		//public string SpecialCharsRepresentation { get; set; }
        private string _SpecialCharsRepresentation;

        public string SpecialCharsRepresentation
        {
            get { return _SpecialCharsRepresentation; }
            set { _SpecialCharsRepresentation = value; }
        }

		
		//public bool IsShowHiddenText { get; set; }
        private bool _IsShowHiddenText;

        public bool IsShowHiddenText
        {
            get { return _IsShowHiddenText; }
            set { _IsShowHiddenText = value; }
        }

		
		//public bool ConvertVisualHyperlinks { get; set; }
        private bool _ConvertVisualHyperlinks;

        public bool ConvertVisualHyperlinks
        {
            get { return _ConvertVisualHyperlinks; }
            set { _ConvertVisualHyperlinks = value; }
        }

		
		//public bool UseNonBreakingSpaces { get; set; }
        private bool _UseNonBreakingSpaces;

        public bool UseNonBreakingSpaces
        {
            get { return _UseNonBreakingSpaces; }
            set { _UseNonBreakingSpaces = value; }
        }

		
		//public string ImagesPath { get; set; }
        private string _ImagesPath;

        public string ImagesPath
        {
            get { return _ImagesPath; }
            set { _ImagesPath = value; }
        }

		
		public string GetImageUrl( int index, RtfVisualImageFormat rtfVisualImageFormat )
		{
			string imageFileName = imageAdapter.ResolveFileName( index, rtfVisualImageFormat );
			return imageFileName.Replace( '\\', '/' );
		} // GetImageUrl

		
		// members
		private readonly IRtfVisualImageAdapter imageAdapter;
		private RtfHtmlCssStyleCollection styles;
		private StringCollection styleSheetLinks;
		private string documentHeader = DefaultDocumentHeader;
		private string characterSet = DefaultDocumentCharacterSet;
	} // class RtfHtmlConvertSettings

}

